/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package httpserver.connections;

import httpserver.users.User;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Bryce
 */
public class ShutdownWorker extends Thread {

    private ArrayList<User> users;
    private ServerSocket listeningSocket;

    public ShutdownWorker(ArrayList<User> users, ServerSocket listeningSocket) {
        this.users = users;
        this.listeningSocket = listeningSocket;
    }

    @Override
    public void run() {
        System.out.println("Disconnecting Users: " + users.size());
        for (User user : users) {
            user.shutdown();
        }
        System.out.println("Disconnecting Listener, port " + listeningSocket.getLocalPort());
        try {
            listeningSocket.close();
        } catch (IOException ex) {
            Logger.getLogger(ShutdownWorker.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
